<extend name="./base" />
<block name="body">
    <link rel="stylesheet" href="/Public/admin/order/order.css">
    <nav class="tab-btn">
        <a href="/Admin/Order/index/tab/1" class="btn <if condition="($tab eq 1) ">active</if>">待审核</a>
        <a href="/Admin/Order/index/tab/2" class="btn <if condition="($tab eq 2) ">active</if>">待付款</a>
        <a href="/Admin/Order/index/tab/3" class="btn <if condition="($tab eq 3) ">active</if>">进行中</a>
        <a href="/Admin/Order/index/tab/4" class="btn <if condition="($tab eq 4) ">active</if>">申请售后</a>
        <a href="/Admin/Order/index/tab/5" class="btn <if condition="($tab eq 5) ">active</if>">已结束</a>
    </nav>
    <table class="table">
        <thead>
        <tr>
            <th>订单号</th>
            <th>学生姓名</th>
            <th>年级</th>
            <th>家长联系方式</th>
            <th>老师联系方式</th>
            <th>老师姓名</th>
            <th>操作</th>
            <th>状态</th>
            <th>添加时间</th>
            <if condition="($tab eq 1)">
                <th>老师是否接单</th>
                <elseif condition="($tab eq 4)"/>
                <th>是否通过用户售后</th>
            </if>
            <th>剩余课时数</th>
            <if condition="($tab eq 3) ">
                <th>更换老师</th>
            </if>
        </tr>
        </thead>
        <tbody>
        <?php $grade_arr = array(1=>"一年级",2=>"二年级",3=>"三年级",4=>"四年级",5=>"五年级",6=>"六年级",7=>"初一",8=>"初二",9=>"初三",10=>"高一",11=>"高二",12=>"高三",);?>
        <foreach name="data" item="vo">
            <tr>
                <td class="order_sn">
                    <if condition="$vo.coursenum elt 2 AND $vo.order_status eq 3"><span style="color: red;">{$vo.order_sn}</span>
                        <else />{$vo.order_sn}
                    </if>
                </td>
                <td>{$vo.name}</td>
                <td><?php echo $grade_arr[$vo['grade']];?></td>
                <td>{$vo.p_phone}</td>
                <td>{$vo.phone}</td>
                <td>{$vo.relname}</td>
                <td><a href="/Admin/Order/detail/id/{$vo.order_id}">详情</a></td>
                <td>
                    <if condition="($vo.order_status eq 1) "> 待审核  </if>
                    <if condition="($vo.order_status eq 2) "> 用户待付款  </if>
                    <if condition="($vo.order_status eq 3) "> 用户已付费  </if>
                    <if condition="($vo.order_status eq 4) "> 用户申请售后审核  </if>
                    <if condition="($vo.order_status eq 5) "> 课程已结束 </if>
                </td>
                <if condition="($vo.order_status eq 1)">
                    <td>
                        <select class="cl_status" name="" id="" data-id="{$vo.order_id}" data-r_id="{$vo.requirement_id}">
                            <option value="0">待审核</option>
                            <option value="2">接单</option>
                            <option value="5">拒绝</option>
                        </select>
                    </td>
                    <elseif condition="($vo.order_status eq 4)"/>
                    <td>
                        <span>用户售后原因：{$vo.reback}</span>
                        <select class="cl_status" name="" id="" data-id="{$vo.order_id}" data-r_id="{$vo.requirement_id}">
                            <option value="0">待审核</option>
                            <option value="5">通过</option>
                            <option value="3">拒绝</option>
                        </select>
                    </td>
                </if>
                <td>{$vo.date}</td>
                <td>{$vo.coursenum}</td>
                <if condition="($tab eq 3) ">
                    <td>
                        <if condition="($vo.change_t egt 2)">
                            -
                            <else />
                            <input type="text" class="techer_id" name="techer_id" value=""><input type="button" class="change" value="更换老师">
                        </if>
                    </td>
                </if>
            </tr>
        </foreach>
        </tbody>
    </table>
    <div class="modal fade" id="changePanel" tabindex="-1" role="dialog" aria-labelledby="FastFindModalLabel" aria-hidden="true">
        <div class="modal-dialog text-center">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close change_cancel" data-dismiss="changePanel" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                    <h4 class="modal-title" id="FastFindModalLabel">教师信息</h4>
                </div>
                <form action="#" id="changeForm" method="post">
                    <p style="margin-top:20px;font-size:20px;">姓名：<span class="new_teacher_name"></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;电话：<span class="new_teacher_phone"></span></p>
                    <a href="javascript:;" class="btn btn-lg btn-block button" data-dismiss="modal" type="submit">确认更换</a>
                    <a href="javascript:;" class="btn btn-lg btn-block change_cancel" >取消</a>
                </form>
            </div>
        </div>
    </div>
    <div>
        {$render}
    </div>
    <script type="text/javascript">
        $(".cl_status").change(function(){
            var this_id = $(this).data("id");
            var this_r_id = $(this).data("r_id");
            var this_status=$(this).val();
            $.ajax({
                type: "post",
                url: "/Admin/Order/deal",
                dataType: 'json',
                data:{
                    order_id:this_id,
                    requriment_id:this_r_id,
                    status:this_status
                },
                success: function(result) {
                    if ( result.flag == 1) {
                        alert('操作成功!');
                        location.reload();
                    } else{
                        alert('操作失败!');
                    }
                }
            })
        });
        var $order_sn;
        var $teacher_id;
        $('.change').on('click',function(){
            $order_sn = $(this).closest("tr").find(".order_sn").text();
            $teacher_id = $(this).prev(".techer_id").val();
            if($(this).prev().val()==''){
                alert("请填写老师编号");
                return false;
            }
            $.ajax({
                type: "post",
                url:"/Admin/teacher/info",
                dataType:'json',
                data:{
                    teacher_id:$teacher_id
                },
                success:function(data){
                    if ( data.error == 1) {
                        alert(data.msg);
                    } else{
                        $('.new_teacher_name').text(data.rs.name);
                        $('.new_teacher_phone').text(data.rs.phone);
                        $('#changePanel').show().addClass('in');
                    }
                }
            });
        });
        $('.change_cancel').click(function(){
            $('#changePanel').hide().removeClass('in');
        });

        $(".button").click(function(){
            $.ajax({
                type: "post",
                url: "/Admin/Order/changeTeacher",
                dataType: 'json',
                data:{
                    teacher_id:$teacher_id,
                    order_sn:$order_sn
                },
                success: function(data) {
                    if ( data.error == 0) {
                        $('#changePanel').hide().removeClass('in');
                        location.reload();
                    } else{
                        alert(data.msg);
                    }
                }
            });
        });
    </script>
    <script type="text/javascript" src="/Public/admin/order/order.js"></script>
</block>
